package edu.pku.sei.transformation.editor.controller.policies;

import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.requests.CreateRequest;

import edu.pku.sei.modeler.model.structure.MetaNode;
import edu.pku.sei.transformation.editor.controller.commands.CommandFactory;
import edu.pku.sei.transformation.editor.controller.commands.node.AdsorbedNodeCreateCommand;
import edu.pku.sei.transformation.editor.controller.commands.node.NestedNodeCreateCommand;
import edu.pku.sei.transformation.editor.model.execution.Pin;

public class TranformationExecutionLayoutPolicy extends
		NestedNodeFlowLayoutPolicy {
	@Override
	protected Command getCreateCommand(CreateRequest request) {
		Rectangle constraint = new Rectangle();
		constraint.setLocation(request.getLocation());
		
		MetaNode parentNode = (MetaNode) getHost().getModel();
		MetaNode subNode = (MetaNode) request.getNewObject();
		Command cmd;
		if (subNode.getModelElement() instanceof Pin) {
			cmd = (AdsorbedNodeCreateCommand) CommandFactory.getCreateCommand(subNode, parentNode, constraint);
		} else {
			cmd = (NestedNodeCreateCommand) CommandFactory
					.getCreateCommand(subNode, parentNode,
							getFeedbackIndexFor(request));
		}
		return cmd;
	}
}
